﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fjaspx.Common;

namespace Fjaspx.UI.Web
{
    public partial class _Reg :UserPage
    {
        /// <summary>
        /// 
        /// </summary>
        private string _Url = null;//登陆后返回URL
        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>The URL.</value>
        public string Url
        {
            get
            {
                if (Request["historyurl"] != null) { _Url = ___WebConfig.web_host + Request["historyurl"] + "?GUID=" + ___WebConfig.GUID; }
                else { _Url = ___WebConfig.web_host + "ucenter/default.aspx"; }
                return _Url;
            }
            set
            {
                _Url = value;
            }
        }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            RegAdd();
        }
        /// <summary>
        /// Handles the Click event of the Button_add control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
       public void RegAdd()
        {   //必填
            string name = Request["name"];//用户名
            string password = Request["password"];//密码
            string email = Request["email"];//邮箱
            string sex = Request["sex"];//性别  
            string valdates = Request["valdates"];//验证码
            //选填
            string qq = Request["qq"];//qq
            int age = int.Parse(Request["age"] == null ? "0" : Request["age"]);//年龄
            string pic = Request["pic"];//头像地址 /开头根目录地址

            if (name != null&&password!=null&&email!=null&&valdates!=null)
            {
                ___ROYcms_user_model.name = name;
                ___ROYcms_user_model.password = password;
                ___ROYcms_user_model.qq = qq;
                ___ROYcms_user_model.email = email;
                ___ROYcms_user_model.age = age;
                ___ROYcms_user_model.sex = sex;
                ___ROYcms_user_model.pic = pic;

                //默认可选参数组
                ___ROYcms_user_model.money = 0;
                ___ROYcms_user_model.quanxian = "Guest";
                ___ROYcms_user_model.username = name;
                ___ROYcms_user_model.RoleID = null;
                ___ROYcms_user_model.UgroupID = null;
                ___ROYcms_user_model.GUID = ___WebConfig.GUID;
                ___ROYcms_user_model.login_time = DateTime.Now;

                if (valdates.Trim().ToUpperInvariant() == Fjaspx.Common.Session.Get("code").ToString().ToUpperInvariant())
                {
                    if (___ROYcms_user_bll.Add(___ROYcms_user_model) != 1)
                    {
                        ___ROYcms_user_model = ___ROYcms_user_bll.GetModel(name);
                        Fjaspx.Common.Session.Add("user_id", ___ROYcms_user_model.bh.ToString().Trim());
                        Fjaspx.Common.Session.Add("user", ___ROYcms_user_model.name.Trim());
                        Fjaspx.Common.Session.Add("ugroup_id", ___ROYcms_user_model.UgroupID.ToString().Trim());

                        MessageBox.ShowAndRedirect(this, "登录成功！将直接转到会员后台！", this.Url);
                        Response.Write("注册成功！<a href='" + this.Url + "'>点击进入" + this.Url + "</a>"); 
                       
                    }
                    else { MessageBox.Show(this, "注册失败！"); Response.Write("注册失败！"); }
                }
                else { MessageBox.Show(this, "验证码错误！"); Response.Write("验证码错误！"); }


            }
            else { MessageBox.Show(this, "缺少参数！");
            Response.Write("缺少参数！");
            } 
        }
        
    }
}
